package com;

import java.util.Objects;

/**
 * Object类：
 *
 */
public class ObjectTest {
    public static void main(String[] args) {
        Student student=new Student(1,"aa",23);
        System.out.println(student.toString());
        Student studen2=new Student(1,"aa",23);
        System.out.println(student.equals(studen2));
        System.out.println(studen2.equals(student));
    }
}

class Student{
    private String name;
    private int sid;
    private int age;
    public  Student(){

    }
    public Student(int sid,String name,int age){
        this.sid=sid;
        this.name=name;
        this.age=age;
    }

    public String toString(){
        return "sid:"+sid+",age:"+age+",name:"+name;
    }


    /**
     * 用于回收
     * @throws Throwable
     */
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }
    @Override
    public boolean equals(Object object){
        if (this==object){
            return true;
        }
        if(object  instanceof Student){
            Student s=(Student) object;
            if (!this.name.equals(s.name)){
                return false;
            }if (this.sid!=s.sid){
                return false;
            }if (this.age!=s.age){
                return false;
            }
                return true;

        }
        return false;
    }
}
